import createStatementData from "./createStatementData";
// 完成代码的拆分
export default function htmlStatement(invoice, plays) {
  return renderHTML(createStatementData(invoice, plays));
}

function renderHTML(data) {
  let res = `【用户${data.customer}的票据单】`;
  for (let perf of data.performance) {
    res += ` ${perf.play.name}: ${usd(perf.amount/100)} (${perf.audience} 座)`;
  }
  res += ` 所欠贷款是 ${usd(data.totalAmount/100)}`;
  res += ` 你赚了 ${data.totalVolumeCredits} 分`;
  return res;
}

function usd(aNumber) {
  return new Intl.NumberFormat("en-US", {style: "currency", currency: "USD", minimumFractionDigits: 2}).format(aNumber)
}